package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.GiveLog;
import com.ruoyi.system.mapper.GiveLogMapper;
import com.ruoyi.system.service.IGiveLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.support.Convert;

/**
 * 赠送记录 服务层实现
 * 
 * @author ruoyi
 * @date 2019-01-06
 */
@Service
public class GiveLogServiceImpl implements IGiveLogService
{
	@Autowired
	private GiveLogMapper giveLogMapper;

	/**
     * 查询赠送记录信息
     * 
     * @param id 赠送记录ID
     * @return 赠送记录信息
     */
    @Override
	public GiveLog selectGiveLogById(Integer id)
	{
	    return giveLogMapper.selectGiveLogById(id);
	}
	
	/**
     * 查询赠送记录列表
     * 
     * @param giveLog 赠送记录信息
     * @return 赠送记录集合
     */
	@Override
	public List<GiveLog> selectGiveLogList(GiveLog giveLog)
	{
	    return giveLogMapper.selectGiveLogList(giveLog);
	}
	
    /**
     * 新增赠送记录
     * 
     * @param giveLog 赠送记录信息
     * @return 结果
     */
	@Override
	public int insertGiveLog(GiveLog giveLog)
	{
	    return giveLogMapper.insertGiveLog(giveLog);
	}
	
	/**
     * 修改赠送记录
     * 
     * @param giveLog 赠送记录信息
     * @return 结果
     */
	@Override
	public int updateGiveLog(GiveLog giveLog)
	{
	    return giveLogMapper.updateGiveLog(giveLog);
	}

	/**
     * 删除赠送记录对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteGiveLogByIds(String ids)
	{
		return giveLogMapper.deleteGiveLogByIds(Convert.toStrArray(ids));
	}

	@Override
	public int give(Map<String,Object> stringObjectMap) {
		int gameUserId = (int) stringObjectMap.get("gameUserId");
		int type = (int) stringObjectMap.get("type");
		int giveCount = (int) stringObjectMap.get("giveCount");
		String createBy =(String) stringObjectMap.get("createBy");
		GiveLog giveLog = new GiveLog();
		giveLog.setGameUserId(gameUserId);
		giveLog.setType(type);
		if(type == 1){
		    giveLog.setRoomCards(giveCount);
        }
        else {
		    giveLog.setGoldCoins(giveCount);
        }
		giveLog.setCreateBy(createBy);
		giveLog.setCreateTime(new Date());
		giveLogMapper.insertGiveLog(giveLog);

		return giveLogMapper.give(stringObjectMap);
	}

	@Override
	public List<GiveLog> selectUserAcountlist(GiveLog giveLog) {
		return giveLogMapper.selectUserAcountlist(giveLog);
	}

	@Override
	public List<Map<String, Object>> qryGiveLogByCreateBy(Map<String, Object> map) {
		return giveLogMapper.qryGiveLogByCreateBy(map);
	}

}
